import requests
from lxml import etree
import re
def get_url():
    result=requests.get("http://www.techlabplt.com/sspu/list1.html")
    result.encoding=result.apparent_encoding
    html=etree.HTML(result.text)
    aHref=html.xpath('//*[@id="yb_h"]/div[3]/div[1]/ul/li/a/@href')
    return aHref
def get_info(url):
    result=requests.get(url)
    result.encoding=result.apparent_encoding
    html=etree.HTML(result.text)
    header=html.xpath('//*[@id="yb_h"]/div[4]/div[1]/a/text()')
    titles = header[0][0:]
    timesinfo=html.xpath('//*[@id="yb_h"]/div[4]/div[4]/span/text()')
    year=re.findall('\d{4}-\d{2}-\d{2}',timesinfo[0])
    times=year[0][0:]
    author = timesinfo[0][19+3:]
    newsCon = re.findall('<div class="neirongye_nr nrr">(.*?)</div>',result.text,re.S)[0]
    newsFormat=re.sub ('<.*?>' , '', newsCon)
    newsFormat=re.sub('&nbsp;','',newsFormat)

    data={
        'title': titles,
        'author':author,
        'time':times,
        'news':newsFormat
            }
     return data
def print_info(data):
    for dictkey,dictvalue in data.items():
        print(dictkey,':',dictvalue)

aHref=get_url()
print(aHref)

for href in aHref:
    print(href)
    if(href.startswith("http://")):
        data = get_info(href)
        print_info(data)
